root_path =  File.expand_path(__FILE__).split('/')[0..-3].join('/')
# 日志
log_file = root_path + '/log/unicorn.log'
err_log  = root_path + '/log/unicorn_error.log'
# 进程标识
pid "#{root_path}/tmp/pids/unicorn.pid"

working_directory root_path

# 通道
socket_file = '/tmp/unicorn_mars.sock'

worker_processes 6
working_directory root_path
timeout 30
# 侦听
preload_app true
listen 5000, tcp_nopush: false
listen socket_file, backlog: 1024

stderr_path err_log
stdout_path log_file


before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = root_path + '/Gemfile'
end

before_fork do |server, worker|
  old_pid = "#{Rails.root}/tmp/pids/unicorn.pid.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
  begin
    Process.kill('QUIT', File.read(old_pid).to_i)
  rescue Errno::ENOENT, Errno::ESRCH
     puts "Send 'QUIT' signal to unicorn error!"
    end
  end
end